package com.yxq.springboot.controller;

import java.util.Date;
import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yxq.springboot.bean.RedisTest1;
import com.yxq.springboot.bean.RedisTest2;
import com.yxq.springboot.bean.User;

/**
 * 远程调用接口，返回json
 * 
 * @ClassName: IndexController
 * @Description:
 * @author xiaoqun.yi yixq@doordu.com
 * @date 2017年3月30日 下午5:11:48
 * @version V1.3
 */
@RestController
@RequestMapping(value = "/index")
public class IndexController {

	private static final Logger logger = LoggerFactory.getLogger(IndexController.class);

	@Autowired
	RedisTest1 redisTest1;

	@Autowired
	RedisTest2 redisTest2;

	@RequestMapping
	public String index() {
		logger.debug("this is a log test, debug");
		logger.info("this is a log test, info");
		redisTest1.setData("yixiaoqun", "test");
		redisTest2.setData("yixiaoqun", "test");
		logger.error("redisTest1:"+redisTest1.getData("yixiaoqun"));
		logger.error("redisTest1:"+redisTest2.getData("yixiaoqun"));
		return "hello world";
	}

	// @RequestParam 简单类型的绑定，可以出来get和post
	@RequestMapping(value = "/get")
	public HashMap<String, Object> get(@RequestParam String name) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("title", "hello world");
		map.put("name", name);
		return map;
	}

	// @PathVariable 获得请求url中的动态参数
	@RequestMapping(value = "/get/{id}/{name}")
	public User getUser(@PathVariable int id, @PathVariable String name) {
		User user = new User();
		user.setId(id);
		user.setName(name);
		user.setDate(new Date());
		return user;
	}

}
